package ACWing.AdvancedGuideAlgorithmicCompetitions.PrimaryAlgorithm.位运算;
//89. a^b

import java.util.Scanner;

/**
 * @author :chenjie
 * @date :Created 2023/1/20 20:25
 */
public class ab {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        int mod=sc.nextInt();
        System.out.println(qmi(a, b, mod));
    }
    public static int qmi(int a,int b,int mod){
        int res=1;
        while (b>0){
            if((b&1)==1){
                res=(int)((long)res*a%mod);
            }
            b=b>>1;
            a=(int)((long)a*a%mod);
        }
        return res%mod;
    }
}
